package com.yoomiito.app.present.home;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.bean.LiveListInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.live.LiveFragment;
import com.yoomiito.app.utils.NetworkUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class LiveFragmentPresenter extends BaseLazyFragmentPresenter<LiveFragment> {
    public LiveFragmentPresenter(AppConfig appConfig) {
        super(appConfig);
    }


    public void getLiveList(int page){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            getV().finishRefresh();
            return;
        }
        YmApi.getYmService()
                .getLiveList(page)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<LiveListInfo>(handleException()) {
                    @Override
                    public void onSuccess(LiveListInfo info) {
                        getV().setListData(info);
                    }

                    @Override
                    public void onFail(ApiException error) {

                    }
                });
    }
}
